#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
bool cmp(const int a, const int b) {
    return a > b;
}
int main(){
    vector<int> a={1,2};
    a.push_back(3);
    a.push_back(4);
    for(auto x:a){
        cout<<x<<' ';
    }
    cout<<endl;
    a.pop_back();
    for(auto x:a){
        x=1+x;
        cout<<x<<' ';
    }
    cout<<endl;
    for(auto x:a){
        cout<<x<<' ';
    }
    cout<<endl;

    cout<<"a longth="<<a.size()<<endl;
    cout<<"a first="<<a.front()<<endl;
    cout<<"a last="<<a.back()<<endl;
    cout<<"a begin迭代器所指对象"<<*a.begin()<<endl;
    cout<<"a end迭代器所指对象"<<*a.end()<<endl;
    cout<<"a[a.size()]="<<a[a.size()]<<endl;
    cout<<"a.at(2)="<<a.at(2)<<endl;

    //cout<<"a.at(3)="<<a.at(3)<<endl;
    //a.at(3)=terminate called after throwing an instance of 'std::out_of_range'
    //what():  vector::_M_range_check: __n (which is 3) >= this->size() (which is 3)
    for(auto x=a.begin();x!=a.end();x++)
        cout<<*x<<' ';
    cout<<endl;
    cout<<"a is empty? ="<<a.empty()<<endl;
    a.clear();
    cout<<"a is empty? ="<<a.empty()<<endl;
    for(auto x=0;x<10;x++){
        auto y=10-x;
        a.push_back(y);
    }
    for(auto x:a){
        cout<<x<<' ';
    }
    cout<<endl;
    sort(a.begin(),a.end());
    for(auto x:a){
        cout<<x<<' ';
    }
    cout<<endl;
    sort(a.begin(),a.end(),cmp);
    for(auto x:a){
        cout<<x<<' ';
    }
    return 0;
}